# -*- coding: utf-8 -*-
# @Time    : 2024/2/1 21:29
# @Author  : micah
# @File    : 11.处理cookie.py
# @Software: PyCharm


from selenium import webdriver


browser = webdriver.Chrome()
browser.get('https://www.baidu.com')

# 获取cookie
cookies = browser.get_cookies()  # 返回的是一个列表
cookie_dict = {item['name']: item['value'] for item in cookies}
print(cookie_dict)

# print(browser.get_cookie('BAIDUID_BFESS'))

# 删除cookie
browser.delete_cookie('BAIDUID_BFESS')
print(browser.get_cookies())

browser.delete_all_cookies()  # 删除所有cookie
print(browser.get_cookies())

# 添加cookie
browser.add_cookie({"name": "顾安", "value": "男"})
print(browser.get_cookies())

browser.quit()